﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Offer_Easy_41_MovingAverage
{
    class MainProject
    {
        static void Main(string[] args)
        {
            //Console.WriteLine(TimeRequiredToBuy(new int[] { 84, 49, 5, 24, 70, 77, 87, 8 }, 3));
            Console.ReadKey();
        }
        public class MovingAverage
        {
            private Queue<int> m_Que = new Queue<int>();
            private int m_Size;
            /** Initialize your data structure here. */
            public MovingAverage(int size)
            {
                m_Size = size;
            }

            public double Next(int val)
            {
                if (m_Que.Count>= m_Size) m_Que.Dequeue();
                m_Que.Enqueue(val);

                double sum = 0;
                foreach (var item in m_Que)
                {
                    sum += item;
                }
                return sum / m_Que.Count;
            }
        }
    }
}
